cmake_minimum_required(VERSION 3.5.0)

project(gtkui)

# 添加编译选项
if (NOT MSVC)
  add_compile_options(-fvisibility=hidden)
else()
  # 对MSVC，默认文件编码为UTF-8，以规避各种编译警告、显示乱码
  # 同时，关闭C4996/C4267告警
  add_compile_options(/utf-8 /wd4996 /wd4267 /wd4103)
endif()

#添加预编译宏
ADD_DEFINITIONS(-DGTK_UI_DLL_EXPORTS)
ADD_DEFINITIONS(-DXML_LIBRARY=${XML_LIBRARY})

#启用当前头文件目录
SET(CMAKE_INCLUDE_CURRENT_DIR ON)

#将各种文件归类到指定变量
FILE(GLOB_RECURSE HEADER_FILES "*.h")
FILE(GLOB_RECURSE SRC_FILES "*.cpp")

#查找当前目录下所有的.h和.cpp文件
SOURCE_GROUP("Header Files" FILES ${HEADER_FILES})
SOURCE_GROUP("Source Files" FILES ${SRC_FILES})

# 库的依赖路径: lib/Win32/Release | lib/Win64/Release | lib/Linux_x86_64/Release
LINK_DIRECTORIES(${PROJECT_LIBRARY_DIR})

# 当前库依赖于当前目录下的源代码/头文件
add_library(${PROJECT_NAME} SHARED ${SRC_FILES} ${HEADER_FILES})

# g++ 检查不允许有未定义的符号
if (NOT MSVC)
  if (${CMAKE_VERSION} VERSION_GREATER 3.13)
      target_link_options(${PROJECT_NAME} PRIVATE -Wl,--disable-new-dtags -Wl,-z,defs)
  else()
      set_target_properties(${PROJECT_NAME} PROPERTIES LINK_FLAGS "-Wl,-z,defs -Wl,--disable-new-dtags")
  endif()
endif()

# 依赖库
if (XML_LIBRARY EQUAL 1)
    target_link_libraries(${PROJECT_NAME} PRIVATE tinyxmlSTL)
elseif (XML_LIBRARY EQUAL 2)
    target_link_libraries(${PROJECT_NAME} PRIVATE tinyxml2)
elseif (XML_LIBRARY EQUAL 3)
    target_link_libraries(${PROJECT_NAME} PRIVATE libxml2)
elseif (XML_LIBRARY EQUAL 4)
    # target_link_libraries(${PROJECT_NAME} PRIVATE rapidxml)
elseif (XML_LIBRARY EQUAL 5)
    # 统一pugixml的库文件名字
    target_link_libraries(${PROJECT_NAME} PRIVATE pugixml)
elseif (XML_LIBRARY EQUAL 6)
    # 统一pugixml的库文件名字
    target_link_libraries(${PROJECT_NAME} PRIVATE roxml)
else()
    message(FATAL_ERROR "Bad XML_LIBRARY: ${XML_LIBRARY}")
endif()

if (NOT WIN32)
    set_target_properties(${PROJECT_NAME} PROPERTIES
      # 固定生成RPATH，并设置RPATH为ELF文件的当前路径
      INSTALL_RPATH "$ORIGIN")
endif()

#引入库目录头文件
INCLUDE_DIRECTORIES(
	${CMAKE_SOURCE_DIR}/include
)

# 安装至特定路径下
install(TARGETS ${PROJECT_NAME} DESTINATION ${CMAKE_INSTALL_BINDIR})
